package com.top.ruizhong;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.PlayerView;

import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FILL;
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIT;
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIXED_HEIGHT;
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH;
import static com.google.android.exoplayer2.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM;

public class CustomPlayerView extends PlayerView {
    public CustomPlayerView(Context context) {
        super(context);
    }

    public CustomPlayerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomPlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);


//        float videoAspectRatio = 9f/16f;
//
//        int width = getMeasuredWidth();
//        int height = getMeasuredHeight();
//        LogUtils.e("width"+((height * videoAspectRatio))+"===height"+(width / videoAspectRatio)+"============widthMeasureSpec" + widthMeasureSpec + "======heightMeasureSpec" + heightMeasureSpec);
//
////width1080===height2210============widthMeasureSpec1073742904======heightMeasureSpec1073744034
//
//
//        super.onMeasure(MeasureSpec.makeMeasureSpec((int) (height * videoAspectRatio), MeasureSpec.EXACTLY),
//                MeasureSpec.makeMeasureSpec((int) (width / videoAspectRatio), MeasureSpec.EXACTLY));




//        if (videoAspectRatio <= 0) {
//            // Aspect ratio not set.
//            return;
//        }
//
//        int width = getMeasuredWidth();
//        int height = getMeasuredHeight();
//        float viewAspectRatio = (float) width / height;
//        float aspectDeformation = videoAspectRatio / viewAspectRatio - 1;
//        if (Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION) {
//            // We're within the allowed tolerance.
//            aspectRatioUpdateDispatcher.scheduleUpdate(videoAspectRatio, viewAspectRatio, false);
//            return;
//        }
//
//        switch (resizeMode) {
//            case RESIZE_MODE_FIXED_WIDTH:
//                height = (int) (width / videoAspectRatio);
//                break;
//            case RESIZE_MODE_FIXED_HEIGHT:
//                width = (int) (height * videoAspectRatio);
//                break;
//            case RESIZE_MODE_ZOOM:
//                if (aspectDeformation > 0) {
//                    width = (int) (height * videoAspectRatio);
//                } else {
//                    height = (int) (width / videoAspectRatio);
//                }
//                break;
//            case RESIZE_MODE_FIT:
//                if (aspectDeformation > 0) {
//                    height = (int) (width / videoAspectRatio);
//                } else {
//                    width = (int) (height * videoAspectRatio);
//                }
//                break;
//            case RESIZE_MODE_FILL:
//            default:
//                // Ignore target aspect ratio
//                break;
//        }//=====================widthMeasureSpec1073742904======heightMeasureSpec1073744034
//        aspectRatioUpdateDispatcher.scheduleUpdate(videoAspectRatio, viewAspectRatio, true);
//        super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
//                MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    }
}
